#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>

int main() 
{
    char path1[PATH_MAX];
    char path2[PATH_MAX];
    // 获取标准输出对应的文件路径
    int result1 = readlink("/proc/self/fd/1", path1, sizeof(path1));
    if (result1 == -1) 
    {
        perror("readlink for stdout");
        return 1;
    }
    path1[result1] = '\0';

    // 获取标准错误对应的文件路径
    int result2 = readlink("/proc/self/fd/2", path2, sizeof(path2));
    if (result2 == -1) 
    {
        perror("readlink for stderr");
        return 1;
    }
    path2[result2] = '\0';

    // 比较两个路径是否相同
    if (strcmp(path1, path2) == 0) 
    {
        printf("Standard output and standard error point to the same file.\n");
        printf("%s\n", path1);
    } 
    else 
    {
        printf("Standard output and standard error do not point to the same file.\n");
    }
    return 0;
} 
